package cn.cjy.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

public class MysqlUtil {
	
	/**
	 * 实现数据查询
	 * @param sql select * from user
	 * @return 返回数据集
	 * @throws SQLException
	 */
	public static ResultSet excuteMysqlSql(String sql) {
	    Connection conn=JDBCConfig.getConnection();
		Statement stmt=null;
		ResultSet rs=null;
		try {
			stmt = conn.createStatement();
			rs=stmt.executeQuery(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return rs;	
	}
	
	/**
	 * insert update delete 方法
	 * @param sql
	 * @return i 影响行数
	 * @throws SQLException
	 */
	public static int excuteMysqlUpdate(String sql)  {
		Connection conn=JDBCConfig.getConnection();
		Statement stmt=null;
		int i=0;
		try {
			stmt = conn.createStatement();
			i=stmt.executeUpdate(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return i;
		
	}
	
	


}
